<template>
  <div class="space">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideWidth" style="min-height: 100vh;background-color: #001529">
        <div style="height: 60px;color:white;display: flex;align-items: center;justify-content: center">
          <img src="../assets/ss_member.png" style="width: 40px;height: 40px">
          <span class="Logo-title" style="margin-left: 5px;font-size: 24px" v-show="!isCollapse">博客管理系统</span>
        </div>
        <el-menu :collapse="isCollapse" :collapse-transition="false" router background-color="#001529"
                 text-color="rgba(255,255,255,0.65)" active-text-color="#fff" style="border: none"
                 :default-active="$router.path">
          <el-menu-item index="/space/">
            <i class="el-icon-house"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>
          <el-submenu index="info" v-if="user.role === '管理员'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/space/userManager">用户信息管理</el-menu-item>
          </el-submenu>
          <el-submenu index="article">
            <template slot="title">
              <i class="el-icon-s-order"></i>
              <span slot="title">文章管理</span>
            </template>
            <el-menu-item index="/space/article">博客文章</el-menu-item>
            <el-menu-item index="/space/articleManager">个人文章管理</el-menu-item>
            <el-menu-item index="/space/likes">点赞管理</el-menu-item>
            <el-menu-item index="/space/comments">评论管理</el-menu-item>
<!--            <el-menu-item index="/space/say">说说管理</el-menu-item>-->
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>

        <!--头部区域-->
        <el-header>
          <i :class="collapseIcon" style="font-size: 26px; " @click="handleCollapse"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left:20px;">
            <el-breadcrumb-item :to="{ path: '/space' }">系统首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: $router.path }">
              {{ $router.history.current.meta.name }}
            </el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex:1; width: 0; display:flex; align-items:center; justify-content:flex-end;">
            <i class="el-icon-full-screen" style="font-size: 26px;" @click="handleFull"></i>
            <el-dropdown placement="bottom">
              <div style="display:flex; align-items:center; cursor: default;">
                <img :src="user.userPic" alt="" style="width: 40px; height: 40px; border-radius: 50%; margin: 0 5px;cursor: pointer">
                <span>{{ user.nickname }}</span>
                <input class="h-combox" style="cursor: pointer">
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$router.push('/space/userInfo')">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/index')">博客首页</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/space/updatePwd')">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="Logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>

        <!--主体区域-->
        <el-main>
          <router-view @update:user="updateUser"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import router from "@/router";

export default {
  name: 'UserSpace',
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem('user-key') || '{}'),
      asideWidth: '200px',
      isCollapse: false,
      collapseIcon: 'el-icon-s-fold',
    }
  },
  methods: {
    Logout() {
      sessionStorage.removeItem('user-key')
      router.push('/login')
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse
      this.asideWidth = this.isCollapse ? '64px' : '200px'
      this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    handleFull() {
      document.documentElement.requestFullscreen()
    },
    updateUser(user) {  //获取子组件传过来的数据，更新当前的数据
      this.user = JSON.parse(JSON.stringify(user)) //让父级的对象跟子级的对象毫无关联
    },
  }
}
</script>

<style scoped>
.el-aside {
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41.35);
}

.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
  padding-left: 75px !important;
}

.el-menu-item:hover,
.el-submenu__title:hover {
  background-color: #001529 !important;
  color: #fff !important;
}

.el-submenu__title:hover i {
  color: #fff !important;
}

.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 5px !important;
  margin: 4px 4px 4px 4px !important;
}

.el-menu-item.is-active i {
  margin-left: -4px !important;
}

.el-menu-item {
  height: 40px !important;
  line-height: 40px !important;
}

.el-submenu__title {
  height: 40px !important;
  line-height: 40px !important;
}

.el-submenu .el-menu-item {
  min-width: 0 !important;
}

.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}

.Logo-title {
  transition: all 0.3s;
}

.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41.35);
  align-items: center;
  display: flex;
}

i {
  cursor: pointer;
}


.user {
  position: relative;
  float: right;
  width: 106px;
  height: 36px;
  padding-right: 50px;
}

.user_abs {
  height: 36px;
  margin-top: 3px;
}


.user_pro {
  border-radius: 12px;
  vertical-align: middle;
  display: inline;
}

.user_username {
  height: 24px;
  margin-left: 6px;
  color: #fff;
  line-height: 24px;
  vertical-align: middle;
  display: inline-block;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.h-combox {
  background: url("../assets/ss_member.png") 0px -115px no-repeat;
  width: 10px;
  height: 10px;
  margin: 6px 0 0 5px;
  vertical-align: middle;
  border: none;
}
</style>
